<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
<script>
$(document).ready(function() {
    var max_fields      = 10; //maximum input boxes allowed
    var wrapper         = $(".input_fields_wrap"); //Fields wrapper
    var add_button      = $(".add_field_button"); //Add button ID
    
    var x = 1; //initlal text box count
    $(add_button).click(function(e){ //on add input button click
        e.preventDefault();
        if(x < max_fields){ //max input box allowed
            x++; //text box increment
            $(wrapper).append('<div><input type="text" onclick="openKCFinder(this)" placeholder="Tạo slide ảnh" style="cursor:pointer" class="form-control" name="slide_product[]"/><a href="#" class="remove_field">Remove</a></div>'); //add input box
        }
    });
    
    $(wrapper).on("click",".remove_field", function(e){ //user click on remove text
        e.preventDefault(); $(this).parent('div').remove(); x--;
    })
});
</script>
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1>
        Quản lý tin bài
      </h1>
      <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i>Admins</a></li>
        <li><a href="#">Tin tức</a></li>
      </ol>
    </section>
    <?php if($temp['mess']!='')
    {
    ?>
    <div class="pad margin no-print">
          <div style="margin-bottom: 0!important;" class="callout callout-info">												
                <?php echo $temp['mess']; ?>
          </div>
    </div>    
    <?php
    }
    ?>
    <!-- Main content -->
    <section class="content">
        <!-- form start -->
        <form role="form" method="POST">
            <input type="hidden" name="ID_NEWS" value="<?php echo  $firstArray['ID_NEWS']; ?>" /> 
            <div class="row">
                    <!-- left column -->
                    <div class="col-md-6">
                      <!-- general form elements -->
                      <div class="box box-primary">
                        <div class="box-header">
                          <h3 class="box-title">Chỉnh sửa tin bài</h3>
                        </div><!-- /.box-header -->
                          <div class="box-body">
                            <!-- Name cat -->
                            <div class="form-group">
                              <label>Tiêu đề bài viết <i class="fa fa-asterisk"></i></label>
                              <input type="text" class="form-control" value="<?php echo  $firstArray['NAME_NEWS']; ?>" placeholder="Tên bài viết không được bỏ trống" name="NAME_NEWS" />
                            </div>                       
                            <!-- select -->
                            <div class="form-group">
                              <label>Danh mục</label>
                              <select class="form-control" name="IDCAT_NEWS">
                                <?php
                                    if(count($allCat) > 0 )
                                    {
                                        echo "<option value='0'>--Chọn danh mục--</option>";
                                        foreach($allCat as $rows)
                                        {
                                        ?>
                                        <option value="<?php echo $rows['IDCAT_NEWS']; ?>" 
                                        <?php
                                            echo ($rows['IDCAT_NEWS'] == $firstArray['IDCAT_NEWS'])?"selected":"";
                                        ?>
                                        ><?php echo  $rows['NAMECAT_NEWS']; ?></option>
                                        <?php                                        
                                        }
                                    }
                                    else
                                    {
                                        echo "<option value='0'>--Chọn danh mục--</option>";
                                    }
                                ?>
                              </select>
                            </div>
                            <div class="form-group">
                              <label>Ảnh đại diện cho tin bài</label>
                            <?php
                                if($firstArray['PHOTO_NEWS'])
                                {
                                ?>
                                <p class="images_upload">
                                <input type="text" class="form-control" readonly="readonly" onclick="openKCFinder(this)"
    placeholder="Click để chọn ảnh" style="cursor:pointer" name="PHOTO_NEWS" value="<?php echo $firstArray['PHOTO_NEWS']; ?>" />     
                                <img width="50" id="PHOTO_NEWS_IMG" src="<?php echo ($firstArray['PHOTO_NEWS']?DOMAIN.$firstArray['PHOTO_NEWS']:DOMAIN."/access/images/no-images.jpg"); ?>" />
                                <i class="fa fa-times" id="PHOTO_NEWS"></i>
                                </p>
                                <?php
                                }
                                else
                                {
                                ?>
                                <input type="text" readonly="readonly" onclick="openKCFinder(this)" placeholder="Click để chọn ảnh" style="cursor:pointer" class="form-control" name="PHOTO_NEWS" />
                                <?php
                                }
                            ?>                              
                            </div>                                                                                                                                             
                          </div><!-- /.box-body -->
                      </div><!-- /.box -->               
                    </div>
                    <!-- right column -->
                    <div class="col-md-6">
                      <!-- general form elements -->
                      <div class="box box-primary">
                        <div class="box-header">
                          <h3 class="box-title">Cấu hình dành cho SEO</h3>
                        </div><!-- /.box-header -->
                          <div class="box-body">                    
                            <!-- SEO -->
                            <div class="form-group">
                              <!-- Name cat seo-->
                              <input type="text" class="form-control" value="<?php echo  $firstArray['NAMESEO_NEWS']; ?>" placeholder="Tên tin bài" name="NAMESEO_NEWS"/>
                            </div>
                            <!-- Des seo -->
                            <div class="form-group">
                                <input type="text" class="form-control" value="<?php echo  $firstArray['DES_NEWS']; ?>" placeholder="Description cho tin bài" name="DES_NEWS"/>
                            </div>
                            <!-- keyword seo -->
                            <div class="form-group">
                                <input type="text" class="form-control" value="<?php echo  $firstArray['KEYWORD_NEWS']; ?>" placeholder="Keyword thêm với dấu phẩy:(điện thoại, di động)" name="KEYWORD_NEWS"/>
                            </div>
                          </div><!-- /.box-body -->
                      </div><!-- /.box -->               
                    </div>              
            </div>          
            <!-- more add -->
            <div class="row">
                <div class="col-md-12">
                    <div class="box box-primary">
                        <div class="box-header">
                          <h3 class="box-title">Thông tin chi tiết cho bài viết</h3>
                        </div><!-- /.box-header -->
                          <div class="box-body">                                                     
                            <div class="form-group">
                              <label>Mô tả vắn tắt</label>
                              <textarea class="form-control" rows="3" name="SUMARY_NEWS" placeholder="Nhập vào mô tả vắn tắt..."><?php echo  $firstArray['SUMARY_NEWS']; ?></textarea>
                            </div>
                            <div class="form-group">
                              <label>Chi tiết bài viết</label>
                              <textarea class="form-control" rows="3" name="CONTENT_NEWS" placeholder="Nhập vào nội dung bài viết..."><?php echo  $firstArray['CONTENT_NEWS']; ?></textarea>
                            </div>
                            <div class="form-group">
                                <input type="text" class="form-control" placeholder="TAGS thêm với dấu phẩy:(siêu phẩm, smartphone giá rẻ)" name="TAGS_NEWS" value="<?php echo  $firstArray['TAGS_NEWS']; ?>"/>
                            </div>
                            <div class="checkbox">
                              <label>
                                <input type="checkbox" name="HOT_NEWS" <?php echo ($firstArray['HOT_NEWS']==1?"checked='checked'":""); ?>  /> Tin Hót
                              </label>
                            </div>                                                        
                            <div class="checkbox">
                              <label>
                                <input type="checkbox" name="STATUS_NEWS" <?php echo ($firstArray['STATUS_NEWS']==1?"checked='checked'":""); ?>  /> Cho phép hiển thị
                              </label>
                            </div>
                            <div class="box-footer">
                                <button class="btn btn-primary" type="submit">Đăng sản phẩm</button>
                            </div>                                                                                                                                                                                                                                                                                                        
                          </div><!-- /.box-body -->                                              
                    </div>
                </div>
            </div>
        </form>        
    </section><!-- /.content -->
    <script>
        // Replace the <textarea id="editor1"> with a CKEditor
        // instance, using default configuration.
        CKEDITOR.replace( 'SUMARY_NEWS' );
        CKEDITOR.replace( 'CONTENT_NEWS' );
    </script>
<script>
    $('form').validate({
        rules: {
       	    NAME_NEWS: {
                required: true
            }
        },
        highlight: function(element) {
            $(element).closest('.form-group').addClass('has-error');
        },
        unhighlight: function(element) {
            $(element).closest('.form-group').removeClass('has-error');
        },
        errorElement: 'span',
        errorClass: 'help-block',
        errorPlacement: function(error, element) {
            if(element.parent('.input-group').length) {
                error.insertAfter(element.parent());
            } else {
                error.insertAfter(element);
            }
        }
    });
    $(document).ready(function(){
        $("#PHOTO_NEWS").click(function(){
            var x;
            if (confirm("Bạn muốn xóa ảnh?") == true) {
                $(".images_upload input[name='PHOTO_NEWS']").val("");
                $( ".images_upload img#PHOTO_NEWS_IMG" ).remove();
            }
        });        
    });    
</script>             
</div><!-- /.content-wrapper -->